<?php
/**订单管理*/
namespace App\Http\Controllers;

use App\Http\Models\Order;
use Illuminate\Http\Request;

class OrderController extends Controller
{
    //用户全部订单
    public function order_list(Request $request)
    {
        $id = $request->input('id');
        $result = Order::OrderList($id);
        if ($result){
            $data = ['code' =>200,'messages' => '请求成功!','result' =>$result];
            return json_encode($data);
        }else{
            $data = ['code' =>400,'messages' => '请求失败!','result' =>''];
            return json_encode($data);
        }
    }
    //用户已完成订单
    public function end_list(Request $request){
        $id = $request->input('id');
        $result = Order::end_orderList($id);
        if (isset($result[0])){
                if (!empty($result[0]->details_length && $result[0]->details_width && $result[0]->details_height && $result[0]->details_name && $result[0]->details_number)){
                    $result = [
                        'orders_orderNo' =>$result[0]->orders_orderNo,
                        'orders_amount' =>$result[0]->orders_amount,
                        'details_orderNo' =>$result[0]->details_orderNo,
                        'details_name' =>$result[0]->details_name,
                        'details_number' =>$result[0]->details_number,
                        'size' => $result[0]->details_length.'x'.$result[0]->details_width.'x'.$result[0]->details_height
                    ];
                }else{
                    $result = [
                        'orders_orderNo' =>$result[0]->orders_orderNo,
                        'orders_amount' =>$result[0]->orders_amount,
                        'details_orderNo' =>$result[0]->details_orderNo,
                        'details_name' =>'',
                        'details_number' =>'',
                        'size' => ''
                    ];
                    $data = ['code' =>400,'messages' => '未知错误！','result' =>$result];
                    return json_encode($data);
                }
            $data = ['code' =>200,'messages' => '请求成功！','result' =>$result];
            return json_encode($data);
        }else{
            $data = ['code' =>201,'messages' => '请求失败！','result' =>''];
            return json_encode($data);
        }
    }
    //用户已支付订单
    public function pay_list(Request $request){
        $id = $request->input('id');
        $result = Order::pay_orderList($id);
        if (isset($result[0])){
            if (!empty($result[0]->details_length && $result[0]->details_width && $result[0]->details_height && $result[0]->details_name && $result[0]->details_number)){
                $result = [
                    'orders_orderNo' =>$result[0]->orders_orderNo,
                    'orders_amount' =>$result[0]->orders_amount,
                    'details_orderNo' =>$result[0]->details_orderNo,
                    'details_name' =>$result[0]->details_name,
                    'details_number' =>$result[0]->details_number,
                    'size' => $result[0]->details_length.'x'.$result[0]->details_width.'x'.$result[0]->details_height
                ];
            }else{
                $result = [
                    'orders_orderNo' =>$result[0]->orders_orderNo,
                    'orders_amount' =>$result[0]->orders_amount,
                    'details_orderNo' =>$result[0]->details_orderNo,
                    'details_name' =>'',
                    'details_number' =>'',
                    'size' => ''
                ];
                $data = ['code' =>400,'messages' => '未知错误！','result' =>$result];
                return json_encode($data);
            }
            $data = ['code' =>200,'messages' => '请求成功！','result' =>$result];
            return json_encode($data);
        }else{
            $data = ['code' =>201,'messages' => '请求失败！','result' =>''];
            return json_encode($data);
        }

    }
    //用户未支付订单
    public function notPay_list(Request $request){

        $id = $request->input('id');
        $result = Order::notPay_orderList($id);
        if (isset($result[0])){
            if (!empty($result[0]->details_length && $result[0]->details_width && $result[0]->details_height && $result[0]->details_name && $result[0]->details_number)){
                $result = [
                    'orders_orderNo' =>$result[0]->orders_orderNo,
                    'orders_amount' =>$result[0]->orders_amount,
                    'details_orderNo' =>$result[0]->details_orderNo,
                    'details_name' =>$result[0]->details_name,
                    'details_number' =>$result[0]->details_number,
                    'size' => $result[0]->details_length.'x'.$result[0]->details_width.'x'.$result[0]->details_height
                ];
            }else{
                $result = [
                    'orders_orderNo' =>$result[0]->orders_orderNo,
                    'orders_amount' =>$result[0]->orders_amount,
                    'details_orderNo' =>$result[0]->details_orderNo,
                    'details_name' =>'',
                    'details_number' =>'',
                    'size' => ''
                ];
                $data = ['code' =>400,'messages' => '未知错误！','result' =>$result];
                return json_encode($data);
            }
            $data = ['code' =>200,'messages' => '请求成功！','result' =>$result];
            return json_encode($data);
        }else{
            $data = ['code' =>201,'messages' => '请求失败！','result' =>''];
            return json_encode($data);
        }
    }
    //用户订单详情
    public function DetailList(Request $request)
    {
        $order_id = $request->input('order_id');
        $result = Order::orderDetail($order_id);
        if (count($result)>0){
            $data = ['code' =>200,'messages' => '请求成功！','result' =>$result];
            return json_encode($data);
        }else{
            $data = ['code' =>201,'messages' => '请求失败！','result' =>''];
            return json_encode($data);
        }
    }
}
